<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>4.简单动画-时序动画-标准动画模型</title>
    <style>
        .container {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            width: 300px;
        }
        .block {
            width: 100px;
            height: 100px;
            margin: 20px;
            flex-shrink: 0;
            transform-origin: 50% 50%;
        }
        .block:nth-child(1) {background: red;border-top:1px solid #000;}
        .block:nth-child(2) {background: blue;border-top:1px solid red;}
        .block:nth-child(3) {background: green;border-top:1px solid #000;}
        .block:nth-child(4) {background: orange;border-top:1px solid #000;}
    </style>
</head>
<body>
    <div class="container">
        <div class="block"></div>
        <div class="block"></div>
        <div class="block"></div>
        <div class="block"></div>
    </div>

    <script type="module">
        import {Animator} from '/common/lib/animator.js';

        const blocks = document.querySelectorAll('.block');
        // duration周期，iterations执行次数
        const animator = new Animator({duration: 1000, iterations: 1.5});
        
        (async function () {
            let i = 0;
            while(true) { // eslint-disable-next-line no-await-in-loop
                await animator.animate(blocks[i++ % 4], ({target, timing}) => {
                    target.style.transform = `rotate(${timing.p * 360}deg)`;
                });
            }
        }());
    </script>
</body>
</html>